package com.xiebishe.mylibrary.common.pageStatus.centerHandler;

import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;

public class FrameLayoutHandler extends CenterStatusHandler<FrameLayout> {

    public FrameLayoutHandler(@NonNull FrameLayout layout) {
        super(layout);
    }

    @Override
    protected void addToCenter(@NonNull View view, @NonNull FrameLayout layout) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams != null) {
            layout.addView(view, 0);
        } else {
            FrameLayout.LayoutParams layoutParams1 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            layoutParams1.gravity = Gravity.CENTER;
            layout.addView(view, 0, layoutParams1);
        }
    }

    @Override
    protected void removeView(@NonNull View view, @NonNull FrameLayout layout) {
        layout.removeView(view);
    }

    @Override
    protected boolean onHideContent(@NonNull FrameLayout layout) {
        setAllInvisible(layout);
        return true;
    }

    @Override
    protected boolean onShowContent(@NonNull FrameLayout layout) {
        restoreLastVisibility(layout);
        return true;
    }
}
